package cn.cuit.ds.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import cn.cuit.ds.domain.User;
import cn.cuit.ds.service.IUserService;
import cn.cuit.ds.service.impl.UserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller
public class AdminAction extends ActionSupport{

	public User user;
	
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public IUserService getService() {
		return service;
	}
	public void setService(IUserService service) {
		this.service = service;
	}
	@Resource(name="UserService")
	IUserService service;
	public String showAll(){
		List<User> usres = service.getAllUsres();
		ServletActionContext.getRequest().setAttribute("allUsers", usres);
		return "showAll";
	}
	
	public String delete(){
		service.deleteUser(user.getUserId());
		return "delete";
	}
	
	public String updateView(){
		User userById = service.getUserById(user.getUserId());
		ServletActionContext.getRequest().setAttribute("user", userById);
		return "updateView";
	}
	
	public String update(){
		service.update(user);
		return "update";
	}
}
